package zhongbo.java.air.ingestion.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.Topic;
import zhongbo.java.air.ingestion.listen.RedisSubscribeLogChannelListener;

@Configuration
@Slf4j
public class RedisListenerConfig {
    public static String FLIGHT_PATH_CHANEL = "flight_path_chanel"; // 此公共常量是频道名

    public static String INJEST_FLIGHT_PATH = "injest_flight_path_tujiapeng";

    public static String LIVE_FLIGHT_PATH = "live_flight_path_tujiapeng";

    /**
     * 配置redis 监听器，添加logChannelListener监听器到容器里，同时指定channel名称为log_chanel
     *
     * @param listenerContainer Redis消息监听容器
     * @param logChannelListener Redis消息监听器
     */
    @Autowired
    public void configListener(RedisMessageListenerContainer listenerContainer, // 管理Redis订阅机制，该容器负责监听Redis频道并分发消息给注册的监听器。
                               RedisSubscribeLogChannelListener logChannelListener) { // 将自定义的RedisSubscribeLogChanelListener添加到监听容器中，使其能够处理来自Redis频道的消息。
        log.info("配置redis监听器");
        Topic logTopic = new PatternTopic(FLIGHT_PATH_CHANEL); // 订阅名为log_chanel的Redis频道
        listenerContainer.addMessageListener(logChannelListener, logTopic); // 将监听器与频道绑定，当该频道有消息时，会触发监听器的onMessage()方法。

//        listenerContainer.addMessageListener(logChannelListener, new PatternTopic(INJEST_FLIGHT_PATH));
    }
}
